﻿using System;
using System.Collections;
using System.Collections.Generic;

using IBatisNet.DataAccess;

using AUV5.Model;
using AUV5.DAL;
using AUV5.DAL.Interface;
using AUV5.DAL.Dao;

namespace AUV5.BLL
{
    /// <summary>
    /// 功能：     OrderLog业务逻辑实现
    /// 作者：     Wilson
    /// 日期：     2011/12/1
    /// 修改日期： 
    /// 修改人：
    /// 修改内容：
    /// </summary>
    public class OrderLogBLL
    {
        private static OrderLogBLL instance = new OrderLogBLL();
        private IDaoManager daoManager = ServiceConfig.Instance.DaoManager;
        private IOrderLogDao dao = null;

        private OrderLogBLL()
        {
            dao = OrderLogSqlMapDao.GetInstance();
        }

        public static OrderLogBLL GetInstance()
        {
            return instance;
        }

        /// <summary>
        /// 得到最大行数
        /// </summary>
        /// <returns></returns>
        public int GetMaxCounts()
        {
            try
            {
                //daoManager.BeginTransaction();

                int count = dao.GetMaxCounts();

                //daoManager.CommitTransaction();

                return count;
            }
            catch
            {
                //daoManager.RollBackTransaction();
                throw;
            }
        }

        /// <summary>
        /// 得到列表
        /// </summary>
        /// <returns></returns>
        public System.Collections.Generic.IList<OrderLog> GetList()
        {
            try
            {
                //daoManager.BeginTransaction();

                System.Collections.Generic.IList<OrderLog> list = dao.GetList();

                //daoManager.CommitTransaction();

                return list;
            }
            catch
            {
                //daoManager.RollBackTransaction();
                throw;
            }
        }

        /// <summary>
        /// 通过不同参数得到列表
        /// </summary>
        /// <param name="TopCounts"></param>
        /// <returns></returns>
        private System.Collections.Generic.IList<OrderLog> GetListByParameters(object TopCounts, OrderLog orderlog)
        {
            try
            {
                //daoManager.BeginTransaction();

                Hashtable ht = new Hashtable();
                ht.Add("TopCounts", TopCounts);
                System.Collections.Generic.IList<OrderLog> list = dao.GetListByParameters(ht);

                //daoManager.CommitTransaction();

                return list;
            }
            catch
            {
                //daoManager.RollBackTransaction();
                throw;
            }
        }


        /// <summary>
        /// 得到明细
        /// </summary>
        /// <param name="HistoryId"></param>
        /// <returns></returns>
        public OrderLog GetDetail(System.String historyid)
        {
            try
            {
                ///daoManager.BeginTransaction();

                return dao.GetDetail(historyid);

                ///daoManager.CommitTransaction();
            }
            catch
            {
                ///daoManager.RollBackTransaction();
                throw;
            }
        }


        /// <summary>
        /// 新建
        /// </summary>
        /// <param name="orderlog"></param>
        /// <returns></returns>
        public object Add(OrderLog orderlog)
        {
            //int id = GetId("SYS_UserInfoTemp");
            //sys_userinfotemp.UserID = id;

            try
            {
                ///daoManager.BeginTransaction();
                orderlog.BeginDate = DateTime.Now;
                orderlog.CreateDate = DateTime.Now;
                orderlog.EndDate = DateTime.Now;
                orderlog.UpdateDate = DateTime.Now;
                orderlog.StatusID = 0;
                orderlog.Title = "";
                orderlog.State = Convert.ToInt32(AUV5.Common.Enum.auvState.Enabled);
                orderlog.State = Convert.ToInt32(AUV5.Common.Enum.auvDel.Del);

                return dao.Add(orderlog);
                ///daoManager.CommitTransaction();
            }
            catch
            {
                ///daoManager.RollBackTransaction();
                throw;
            }
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="orderlog"></param>
        /// <returns></returns>
        public int Update(OrderLog orderlog)
        {
            try
            {
                ///daoManager.BeginTransaction();

                return dao.Update(orderlog);

                ///daoManager.CommitTransaction();
            }
            catch
            {
                ///daoManager.RollBackTransaction();
                throw;
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="HistoryId"></param>
        /// <returns></returns>
        public int Delete(System.String historyid)
        {
            try
            {
                ///daoManager.BeginTransaction();

                return dao.Delete(historyid);

                ///daoManager.CommitTransaction();
            }
            catch
            {
                ///daoManager.RollBackTransaction();
                throw;
            }
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="orderlog"></param>
        /// <returns></returns>
        public int Delete(OrderLog orderlog)
        {
            try
            {
                ///daoManager.BeginTransaction();

                return dao.Delete(orderlog);

                ///daoManager.CommitTransaction();
            }
            catch
            {
                ///daoManager.RollBackTransaction();
                throw;
            }
        }

        #region##通地订单ID得到订单聊天集合
        /// <summary>
        /// 通地订单ID得到订单聊天集合
        /// 创建人：Wilson
        /// 创建时间：2011-12-2
        /// </summary>
        /// <param name="objParameters"></param>
        /// <returns></returns>
        public IList<OrderLog> GetListByOrderId(string orderId)
        {
            try
            {
                Hashtable ht = new Hashtable();
                ht.Add("OrderId", orderId);
                ht.Add("State", Convert.ToInt32(AUV5.Common.Enum.auvState.Enabled));
                ht.Add("IsDel", Convert.ToInt32(AUV5.Common.Enum.auvDel.NotDel));
                return dao.GetListByOrderId(ht);
            }
            catch
            {
                throw;
            }
        }
        #endregion
    }
}
